<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>Hello MUI</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<!--标准mui.css-->
		<link rel="stylesheet" href="../../../css/mui.min.css">
		<style>
			h5 {
				margin: 5px 7px;
			}
			.mui-action-back:before{
				content: "\e582"!important;
			}
			.mui-action-back{
				color:#fff;
			}
			.mui-btn.mui-btn-link{
				color:#fff; 
			}
			#inputName{
				border:none;
				border-bottom:solid 1px #ccc;
				background:none;
				border-radius:none;
			}
		</style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav" style="background-color: #fff;box-shadow: none; border-bottom: solid 1px #dfdfdf;">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left" style="color: #000; padding-left: 0;"></a>
			<h1 class="mui-title" style="color:#000;"><span id="typeName"></span></h1>
			<a class="mui-btn mui-btn-link mui-pull-right" style="color: #000;" id="savebtn">保存</a>
		</header>
		<div class="mui-content">
			<div class="mui-content-padded" style="margin: 5px;">
				<div class="mui-input-row mui-password">
					<input id="inputName" autofocus="autofocus" type="text" class="mui-input-text">

				</div>
			</div>
		</div>
		<script src="../../../js/mui.min.js"></script>
		<script src="../../../js/vue.min.js"></script>
		<script src="../../../js/app.js"></script>
		<script src="../../../js/token.js"></script>
		<script src="../../../js/jquery-1.8.3.min.js"></script>	
		<script>
			mui.init({
				swipeBack: true //启用右滑关闭功能
			});

			var nativeWebview, imm, InputMethodManager;
			var initNativeObjects = function() {
				if (mui.os.android) {
					var main = plus.android.runtimeMainActivity();
					var Context = plus.android.importClass("android.content.Context");
					InputMethodManager = plus.android.importClass("android.view.inputmethod.InputMethodManager");
					imm = main.getSystemService(Context.INPUT_METHOD_SERVICE);
				} else {
					nativeWebview = plus.webview.currentWebview().nativeInstanceObject();
				}
			};
			var showSoftInput = function() {
				if (mui.os.android) {
					imm.toggleSoftInput(0, InputMethodManager.SHOW_FORCED);
				} else {
					nativeWebview.plusCallMethod({
						"setKeyboardDisplayRequiresUserAction": false
					});
				}
				setTimeout(function() {
					var inputElem = document.querySelector('input');
					inputElem.focus();
					inputElem.parentNode.classList.add('mui-active'); //第一个是search，加上激活样式
				}, 200);
			};
			var uid='';
			var state='';
			
			mui.plusReady(function() {
				var self=plus.webview.currentWebview();
				state=app.getState();
				memberToken = state.memberToken;
				uid=state.userid;
				type=self.type;
				childid = state.childid
				setTimeout(function() {
				initNativeObjects();
				showSoftInput();
				},50)
				var typeName=plus.webview.currentWebview().name;
				var inputName=plus.webview.currentWebview().inputName;
				document.getElementById('typeName').innerHTML='更改'+typeName;
				document.getElementById('inputName').value=inputName;
			});
			document.getElementById('savebtn').addEventListener('tap',function(){
				
				if(type==1){
						
					mui.post(Apiurl+'index/member_info', {
						uid: uid,
						child_name:document.getElementById('inputName').value,
						memberToken: memberToken,
						child_id: childid 
					}, function(data) {
						if(data.status==200){
							plus.nativeUI.toast('修改成功', {
											verticalAlign: 'middle'
										});
							mui.fire(plus.webview.getWebviewById("userinfoindex"),'refreshuserinfo',{
								type:self.type, 
								modify:document.getElementById('inputName').value
							})             
							mui.fire(plus.webview.getWebviewById("pcenter"),'refreshuserinfo',{
								type:self.type,
								modify:document.getElementById('inputName').value
							})
							plus.webview.currentWebview().close();
						}else if(data.status==404){
							plus.nativeUI.toast('您的输入不合法', {
											verticalAlign: 'middle'
										});
						}else if(data.status==405){
							plus.nativeUI.toast('修改异常', {
											verticalAlign: 'middle'
										});
						}
						
					}, 'json');
				}else if(type==2){
				
					var sMobile = document.getElementById('inputName').value 
					 if(!(/^1[3|4|5|7|8][0-9]\d{4,8}$/.test(sMobile))){ 
					 alert("您输入的手机号有误"); 
					 document.getElementById('inputName').focus(); 
					 return false; 
					 }else{
					 	mui.post(Apiurl+'index/member_info', {
						uid: uid,
						tel:document.getElementById('inputName').value,
						memberToken : memberToken
						}, function(data) {
							if(data.status==200){
							plus.nativeUI.toast('修改成功', {
											verticalAlign: 'middle'
										});
						}
						}, 'json');
					 }
				}else if(type==4){
				
					mui.post(Apiurl+'index/member_info', {
						uid: uid,
						child_name:document.getElementById('inputName').value,
						memberToken: memberToken,
						child_id:childid
						}, function(data) {
							if(data.status==200){
							plus.nativeUI.toast('修改成功', {
											verticalAlign: 'middle'
										});
							mui.fire(plus.webview.getWebviewById("userinfoindex"),'refreshuserinfo',{
								type:self.type, 
								modify:document.getElementById('inputName').value
							})             
							mui.fire(plus.webview.getWebviewById("pcenter"),'refreshuserinfo',{
								type:self.type,
								modify:document.getElementById('inputName').value
							})
							plus.webview.currentWebview().close();
						}else if(data.status==404){
							plus.nativeUI.toast('您的输入不合法', {
											verticalAlign: 'middle'
										});
						}else if(data.status==405){
							plus.nativeUI.toast('修改异常', {
											verticalAlign: 'middle'
										});
						}
						}, 'json');
				} 
				
					
			})
			
		</script>
	</body>

</html>